package com.movecar.ui;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.ImageView;

import com.movecar.R;

public class BitmapActivity extends Activity {
	private int date[];
	private int date_id = 0;;
	private ImageView mImageView;
	private Handler handler;
	private Thread t;
	private boolean isRun = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {

		}
		setContentView(R.layout.anim_image);
		mImageView = (ImageView) findViewById(R.id.image_view);
		handler = new Handler();
		date_id = 0;
		this.init();

	}

	public void init() {
		date = new int[60];
		for (int j = 0; j < date.length; j++) {
			date[j] = R.drawable.beans_progress_1 + j;
		}

		t = new Thread() {
			@SuppressWarnings("static-access")
			public void run() {
				while (isRun) {
					try {
						date_id += 1;
						if (date_id >= date.length) {

							isRun = false;
							finish();
						} else {
							Log.e("date_id", String.valueOf(date_id));

							handler.post(runnableUi);

							t.sleep(80);
						}

					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		};
		t.start();

	}

	Runnable runnableUi = new Runnable() {
		@Override
		public void run() {
			// 更新界面
			mImageView.setImageResource(date[date_id]);
			mImageView.invalidate();

		}

	};

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
			isRun = false;
		}
		return super.onKeyDown(keyCode, event);
	}
}
